/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Services;

import Entitys.Artist;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author Administrador
 */
public class ArtistDAO {
    private static final EntityManagerFactory emf= Persistence.createEntityManagerFactory("GRLPU");
    private static final EntityManager em=emf.createEntityManager();
    
    public void create(Artist art){
        em.getTransaction().begin();
        try {
            em.persist(art);
            em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }
    
    public boolean delete(Artist art) {

        
        em.getTransaction().begin();
        Artist a= em.find(Artist.class, art.getId());
        boolean ret = false;
        try {
            em.remove(a);
            em.getTransaction().commit();
            ret = true;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
            return ret;
        }
    }
    
    
}
